
-- 	跳过字符串开头的空白
--	返回跳过后的字符串
function skipHeadSpace(skipString)
	local headp =1
	while 1 do
		local byte = string.byte(skipString,headp)
--		print(skipString,byte)
		if 32 ~= byte then 
			break
		end
		headp = headp +1
	end
	skipString = string.sub(skipString,headp)
	return skipString
end

OStypestring = os.getenv("OS")
print( "I am working under",OStypestring)
SourceTable={}

--	windows的环境下用dir命令查找c文件
local tmpfileName = "___myfilelist.txt"
local p,q = string.find(OStypestring,"Windows")
if p then
	os.execute(string.format('%s%s',"dir > ",tmpfileName))
	io.input(tmpfileName)
	local lineCouter = 1
	for line in io.lines() do
		line = skipHeadSpace(line)
		local dirp,dirq = string.find(line,"<DIR>")
		if dirp then
			print("Skip directory",line)
		end
		local sourcep,sourceq = string.find(line,"C:")
		if sourcep then
			print("Skip directory",line)
		end
		local sourcep,sourceq = string.find(line,".c")
		if sourcep and lineCouter > 4 then
--			print(".c fils",line)
			local source = string.sub(line,37)
			table.insert(SourceTable,source)
		end
		lineCouter = lineCouter + 1
	end
--	io.close()
--	os.execute(string.format('%s%s',"del ",tmpfileName))
end
--	linux 环境用下用·ls命令查找c文件


--------------------------------------------------------------------------------------------------------------------------------------------------
--	生成可执行文件
local src = table.concat(SourceTable," ")
addcomand_t = {"add_library ( tmp",src,") \n"}
local addcomandStr = table.concat(addcomand_t," ")
io.output("LLMakeLists.txt")
io.write(addcomandStr)
io.close()
